﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;

using GeneralTool.CoreLibrary.Attributes;
using GeneralTool.CoreLibrary.Extensions;
using GeneralTool.CoreLibrary.Models;
using GeneralTool.CoreLibrary.ProcessHelpers;
using GeneralTool.CoreLibrary.TaskLib;
using GeneralTool.CoreLibrary.Win32;
using GeneralTool.CoreLibrary.WPFHelper;


namespace TaskServerUI
{
    public interface ITestTask
    {
        string TestString(int a = 0);
        string TestString([WaterMark("名称")] string name);
    }

    [Route("TestTask/", "测试接口")]
    public class TestTask : BaseTaskInvoke, ITestTask
    {
        [Route(nameof(TestString), "测试字符串", method: HttpMethod.POST)]
        public string TestString([WaterMark("随意命名")] int a = 0)
        {
            return Guid.NewGuid().ToString();
        }

        [Route(nameof(TestString), "测试字符串(重载接口)", Method = HttpMethod.POST, RouteVisibleEditor = typeof(RouteVisible))]
        public string TestString([WaterMark("名称")] string name)
        {
            Thread.Sleep(5000);
            return "hello:" + name;
        }


        [Route(nameof(Test22))]
        public object Test22(string a)
        {
            return new { a.Length };
        }

        [Route(nameof(GetFiles))]
        public byte[] GetFiles(string filePath)
        {
            return File.ReadAllBytes(filePath);
        }

        [Route(nameof(UploadFile))]
        public void UploadFile(string fileName, byte[] bytes)
        {
            File.WriteAllBytes(fileName, bytes);
        }

        [Route(nameof(TaskWait))]
        public async Task TaskWait()
        {
            await Task.Delay(5000);
        }

        [Route(nameof(TaskStringAsync))]
        public async Task<string> TaskStringAsync([WaterMark("name")] string name)
        {
            await Task.Delay(1000);
            return $"Hello _ {name}";
        }

        [Route(nameof(ExObject))]
        public AdbBlockModel ExObject(AdbBlockModel block)
        {
            return block;
        }

        [Route(nameof(GetRequestInfo))]
        public RequestCommand GetRequestInfo(RequestCommand requestInfo)
        {
            requestInfo.ClassName = "Test";
            return requestInfo;
        }

        public AdbBlockModel Model { get; set; }

        [Route(nameof(ThrowEx))]
        public void ThrowEx()
        {
            throw new NotImplementedException();
        }


    }


    public class PostParameter
    {
        public string BlockName { get; set; }
        public List<Dictionary<string, object>> parameterJsonValue { get; set; }
    }

    public class RouteVisible : RouteVisibleEditor
    {
        public override bool Visible()
        {
            return true;
        }
    }

    public class AdbBlockModel : BaseNotifyModel
    {
        private int id;
        public int Id
        {
            get => this.id;
            set => this.RegisterProperty(ref this.id, value);
        }

        private int refValId;

        public int RefValId
        {
            get => this.refValId;
            set => this.RegisterProperty(ref this.refValId, value);
        }



        private int executeType;
        /// <summary>
        /// 执行模式
        /// </summary>
        public int ExecuteType
        {
            get => this.executeType;
            set => this.RegisterProperty(ref this.executeType, value);
        }

        private int snapType;
        /// <summary>
        /// 采集模式,同步或异步
        /// </summary>
        public int SnapType
        {
            get => this.snapType;
            set => this.RegisterProperty(ref this.snapType, value);
        }

        private string adbCommandTxt;
        /// <summary>
        /// adb命令
        /// </summary>
        public string AdbCommandTxt
        {
            get => this.adbCommandTxt;
            set => this.RegisterProperty(ref this.adbCommandTxt, value);
        }

        private bool isOutFile;
        /// <summary>
        /// 是否输出到文件
        /// </summary>
        public bool IsOutFile
        {
            get => this.isOutFile;
            set => this.RegisterProperty(ref this.isOutFile, value);
        }

        private string outPutFilePath;
        /// <summary>
        /// 否输出到文件的路径
        /// </summary>
        public string OutPutFilePath
        {
            get => this.outPutFilePath;
            set => this.RegisterProperty(ref this.outPutFilePath, value);
        }

        private bool addDate;
        /// <summary>
        /// 每条输出是否加入日期参数
        /// </summary>
        public bool AddDate
        {
            get => this.addDate;
            set => this.RegisterProperty(ref this.addDate, value);
        }

        private string dateFomart = "yyyy-MM-dd HH:mm:ss.fff";
        /// <summary>
        /// 日期参数格式
        /// </summary>
        public string DateFomart
        {
            get => this.dateFomart;
            set => this.RegisterProperty(ref this.dateFomart, value);
        }
    }
}
